package com.zhxy.util.publish;

import java.util.concurrent.atomic.AtomicLong;


public class SimplePublisher<P> extends AbstractPublisher<P> implements Publisher<P> {
	
	private AtomicLong subscribersCount = new AtomicLong(0);
	
	public long getSubscribeCount() {
		return subscribersCount.get();
	}

	public void publish(String name, P pub) {
		doPublish(name, pub);
	}

	@Override
	public void subscribe(Subscriber<P> subscriber, String name) throws SubscribeException {
		doSubscribe(subscriber, name);
		subscribersCount.incrementAndGet();
	}

	@Override
	public void unsubscribe(Subscriber<P> subscriber, String name) throws SubscribeException {
		doUnsubscribe(subscriber, name);
		subscribersCount.decrementAndGet();
	}

	@Override
	public void cleanSubscribe(Subscriber<P> subscriber) throws SubscribeException {
		doCleanSubscribe(subscriber);
	}

}
